home *** CD-ROM | disk | FTP | other *** search
- Path: wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!cs.odu.edu!Amiga-Request
- From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
- Newsgroups: comp.sources.amiga
- Subject: v90i149: MemMometer 2.1 - memory fragmentation gauge, Part02/02
- Message-ID: <12222@xanth.cs.odu.edu>
- Date: 15 Apr 90 14:51:23 GMT
- Sender: tadguy@cs.odu.edu
- Reply-To: hull@hao.ucar.edu (Howard Hull)
- Lines: 1091
- Approved: tadguy@cs.odu.edu (Tad Guy)
- X-Mail-Submissions-To: Amiga@cs.odu.edu
- X-Post-Discussions-To: comp.sys.amiga
-
- Submitted-by: hull@hao.ucar.edu (Howard Hull)
- Posting-number: Volume 90, Issue 149
- Archive-name: util/memmometer-2.1/part02
-
- #!/bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 2 (of 2)."
- # Contents: mm.c
- # Wrapped by tadguy@xanth on Sun Apr 15 10:49:57 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'mm.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'mm.c'\"
- else
- echo shar: Extracting \"'mm.c'\" \(35050 characters\)
- sed "s/^X//" >'mm.c' <<'END_OF_FILE'
- X/* : ai=0 bk=0 ts=8 */
- X#include "mm.h"
- X
- X#define FREEPEN -1L /* workbench screen default colors */
- X#define REQ_WINDOW_WIDTH 319L /* width of SFMem warning requester window */
- X#define REQ_WINDOW_HEIGHT 79L /* height of SFMem warning requester window */
- X
- X#define SOK 0x001f /* memory allocation control masks */
- X#define S1 0x0001
- X#define S2 0x0002
- X#define S4 0x0004
- X#define S8 0x0008
- X#define SA 0x0010
- X#define C1 0xfffe
- X#define C2 0xfffd
- X#define C4 0xfffb
- X#define C8 0xfff7
- X#define CA 0xffef
- X#define AARRRGH 20L
- X
- X#define EXTENSION 16L /* allocation request increment */
- X
- X#define FRAGS FALSE /* frags mode control boolian */
- X#define WARPS TRUE /* warps mode control boolian */
- X#define EVENMASK 0x7ffffffe /* used to prevent odd address traps */
- X#define CLIHEIGHT 200L /* window scaling stuff */
- X#define SIZEGAD 9L
- X#define DRAGBAR 10L
- X#define BORDER 2L
- X#define WINW 16L /* initial window width */
- X#define WINH (long)(CLIHEIGHT - SIZEGAD - DRAGBAR) /* initial win height */
- X#define MINH 81L /* shortest allowable window */
- X#define MAXH 576L /* longest allowable window */
- X#define BART 1L /* title bar F text location */
- X#define BARH (long)(WINH - SIZEGAD - DRAGBAR) /* bar height */
- X#define BARS (long)(BARH + 1) /* number of memory items to allocate */
- X#define BARB (long)(BARH + DRAGBAR - 1) /* bottom of mercury column */
- X#define BARE (long)(BARB + BORDER) /* bar end E text position */
- X#define BARW (long)(((WINW - (2 * BORDER)) / 3) - 1) /* 3 memfragmometers */
- X#define LEFT BORDER /* SLOW : since we're syncopated, we */
- X#define MIDDLE (LEFT + BARW + 1) /* SLOW-FAST : do it going from bar */
- X#define RIGHT (MIDDLE + BARW + 1) /* FAST :to bar at an irregular pace */
- X#define RTEXT - 4L /* offset for three char E/F text from left edge */
- X#define STARTVAL 64L /* start by getting enough storage for a few frags */
- X
- X/* typedef short BOOL */ /* this is in include/exec/types.h */
- X
- Xstruct IntuitionBase *IntuitionBase=NULL ;
- Xstruct Window *window ;
- Xstruct IntuiMessage *message;
- X/* struct IntuiMessage *GetMsg(); */ /* in functions.h */
- X
- Xstruct GfxBase *GfxBase=NULL ;
- X
- Xstruct IOStdReq *timermsg=NULL;
- Xstruct MsgPort *timerport=NULL;
- XULONG timerbit=NULL;
- X
- X
- Xextern void InitProjItems(); /* this stuff is in the mminit section */
- Xextern void InitSetupItems();
- Xextern void InitPrioItems();
- Xextern void InitChipItems();
- Xextern void InitChipAItems();
- Xextern void InitSFItems();
- Xextern void InitSFAItems();
- Xextern void InitFastItems();
- Xextern void InitFastAItems();
- Xextern void InitMenu();
- Xextern void StartMenus();
- X
- XBOOL p_mode = FRAGS; /* preset frags mode = 0, warps mode = 1 */
- X /* note: mode preset used as request for */
- X /* change to warps mode after the */
- X /* first pass with frags mode set! */
- Xlong p_rate = 2; /* preset sample interval, secs see menu */
- Xlong p_priority = 0; /* preset priority, range -128 to +127 */
- X /* note: pri greater than zero is risky! */
- X /* keep in mind AmigaDOS priorities: */
- X /* input.device 20, FileSystem 10, and */
- X /* trackdisk.device, CON: 5 also if MM */
- X /* is started from a CLI without the Run */
- X /* then that CLI inherits MM's priority! */
- Xlong p_chip = 512; /* preset chip mem size, kbytes see menu */
- Xlong p_chipa = 0; /* preset chip mem address, kb see menu */
- Xlong p_sf = 0; /* preset slowfast mem size, kb see menu */
- Xlong p_sfa = 0x3000; /* preset slowfast mem addr, kb see menu */
- Xlong p_fast = 0; /* preset fast mem size, mbytes see menu */
- Xlong p_fasta = 2; /* preset fast mem addr, mbytes see menu */
- X
- Xstatic BOOL mode; /* uninitialized for mode control */
- Xstatic BOOL mmode; /* uninitialized for mode menu */
- Xstatic long delayval; /* uninitialized for delay menu */
- Xstatic long priority; /* uninitialized for priority menu */
- Xstatic long lastpri; /* uninitialized for priority incr */
- Xstatic long cmemsize; /* uninitialized for chip menu */
- Xstatic long cmembase; /* uninitialized for chipa menu */
- Xstatic long sfmemsize; /* uninitialized for sf menu */
- Xstatic long sfmembase; /* uninitialized for sfa menu */
- Xstatic long fmemsize; /* uninitialized for fast menu */
- Xstatic long fmembase; /* uninitialized for fasta menu */
- X
- Xstatic USHORT log ; /* memory allocation success flags */
- Xstatic BOOL things_are_cool = TRUE ; /* tells when to close the window */
- Xstatic BOOL intsig = FALSE ; /* intuition message detector */
- Xstatic USHORT chgflag = TRUE ; /* menu request to adjust columns */
- Xstatic long chip[3], fast[3] ; /* place to keep mem header pointers */
- Xstatic ULONG *chunkv ; /* demand allocated for frag chunks */
- Xstatic ULONG *sizev ; /* demand allocated for frag sizes */
- Xstatic ULONG *csum ; /* a col's height worth of checksums */
- Xstatic ULONG *oldcsum ; /* same height worth of old checksums */
- Xstatic USHORT *cell; /* 1 cell per pixel height of mercury */
- Xstatic long xl, xr ; /* used to Draw() memometer segments */
- Xstatic long frags = STARTVAL ; /* # of demand allocated frag items */
- Xstatic long warps = BARS ; /* # of demand allocated column items */
- Xstatic long barh = BARH ; /* EVEN #'d height of mercury column */
- Xstatic long barb = BARB ; /* bottom position of mercury column */
- X
- X/* struct RastPort *rp ; */ /* wonder why we don't need this... ? */
- X
- X
- Xstatic struct TextAttr myfont = {
- X (STRPTR) "topaz.font",
- X TOPAZ_EIGHTY,
- X 0,
- X 0
- X};
- X/* E newsize gadget refresh text */
- Xstatic char ebuf[4] = " E " ;
- Xstatic struct IntuiText e_text = {
- X BLUP, WHTP,
- X JAM2,
- X 0, BARE,
- X &myfont,
- X (UBYTE *)ebuf,
- X NULL
- X};
- X/* F title refresh text */
- Xstatic char fbuf[4] = " F " ;
- Xstatic struct IntuiText f_text = {
- X BLUP, WHTP,
- X JAM2,
- X 0, BART,
- X &myfont,
- X (UBYTE *)fbuf,
- X &e_text
- X};
- Xstatic struct NewWindow newwindow = {
- X 0, /* left edge */
- X 10, /* top edge */
- X WINW, /* width */
- X WINH, /* height */
- X 0, /* detail pen */
- X 1, /* block pen */
- X MENUPICK | NEWSIZE, /* messages */
- X/* WINDOWDEPTH | WINDOWCLOSE */ /* don't use these gads */
- X WINDOWDRAG | WINDOWSIZING | SMART_REFRESH, /* add a few gadgets */
- X NULL, /* no custom gadgets */
- X NULL, /* default checkmark */
- X (UBYTE *)"F", /* title */
- X NULL, /* initialize this! */
- X NULL, /* use screen bitmap */
- X WINW, MINH, WINW, MAXH, /* min and max sizes */
- X WBENCHSCREEN } ; /* use workbench screen */
- X
- Xvoid initmenus()
- X{
- X (void) InitProjItems(); /* Initialize the menu items */
- X (void) InitSetupItems();
- X (void) InitPrioItems();
- X (void) InitChipItems();
- X (void) InitChipAItems();
- X (void) InitSFItems();
- X (void) InitSFAItems();
- X (void) InitFastItems();
- X (void) InitFastAItems();
- X (void) InitMenu();
- X (void) StartMenus();
- X }
- X
- Xvoid handle_MENUPICK( class, code )
- Xunsigned long class;
- Xunsigned int code;
- X{
- X unsigned int menunum, itemnum, subnum;
- X
- X if (code == MENUNULL) return;
- X
- X menunum = MENUNUM( code );
- X itemnum = ITEMNUM( code );
- X subnum = SUBNUM( code );
- X chgflag = TRUE;
- X switch( menunum ) {
- X case 0:
- X switch( itemnum ) {
- X case 0:
- X WindowToFront(window);
- X break;
- X
- X case 1:
- X WindowToBack(window);
- X break;
- X
- X case 2:
- X things_are_cool = FALSE; /* Quit */
- X break;
- X } /* end of switch ( Project itemnum ) */
- X break;
- X
- X case 1:
- X switch( itemnum ) {
- X case 0:
- X switch( subnum ) {
- X case 0:
- X mode = FRAGS ; /* Frags mode */
- X break;
- X
- X case 1:
- X mmode = TRUE ; /* Warps request */
- X break;
- X /* end of switch ( Mode subnum ) */
- X }
- X break;
- X case 1:
- X switch( subnum ) {
- X case 0:
- X delayval = 1;
- X break;
- X
- X case 1:
- X delayval = 2;
- X break;
- X
- X case 2:
- X delayval = 5;
- X break;
- X
- X case 3:
- X delayval = 10;
- X break;
- X /* end of switch ( Freq subnum ) */
- X }
- X break;
- X /* end of switch ( Setup itemnum ) */
- X }
- X break;
- X
- X case 2:
- X switch( itemnum ) {
- X case 0:
- X priority = lastpri;
- X break;
- X
- X case 1:
- X priority = priority - 1;
- X break;
- X
- X case 2:
- X priority = priority + 1;
- X break;
- X
- X case 3:
- X priority = -99;
- X lastpri = priority;
- X break;
- X
- X case 4:
- X priority = -75;
- X lastpri = priority;
- X break;
- X
- X case 5:
- X priority = -50;
- X lastpri = priority;
- X break;
- X
- X case 6:
- X priority = -25;
- X lastpri = priority;
- X break;
- X
- X case 7:
- X priority = -20;
- X lastpri = priority;
- X break;
- X
- X case 8:
- X priority = -15;
- X lastpri = priority;
- X break;
- X
- X case 9:
- X priority = -10;
- X lastpri = priority;
- X break;
- X
- X case 10:
- X priority = -5;
- X lastpri = priority;
- X break;
- X
- X case 11:
- X priority = 0;
- X lastpri = priority;
- X break;
- X
- X case 12:
- X priority = 5;
- X lastpri = priority;
- X break;
- X
- X case 13:
- X priority = 10;
- X lastpri = priority;
- X break;
- X
- X case 14:
- X priority = 15;
- X lastpri = priority;
- X break;
- X
- X case 15:
- X priority = 20;
- X lastpri = priority;
- X break;
- X }
- X /* end of switch ( Priority itemnum ) */
- X break;
- X
- X case 3:
- X switch( itemnum ) {
- X case 0:
- X cmemsize = 0x000000;
- X break;
- X
- X case 1:
- X cmemsize = 0x040000;
- X break;
- X
- X case 2:
- X cmemsize = 0x080000;
- X break;
- X
- X case 3:
- X cmemsize = 0x100000;
- X break;
- X
- X case 4:
- X cmemsize = 0x200000;
- X break;
- X }
- X /* end of switch ( Chip Size itemnum ) */
- X break;
- X
- X case 4:
- X switch( itemnum ) {
- X case 0:
- X cmembase = 0x000000;
- X break;
- X
- X case 1:
- X cmembase = 0x040000;
- X break;
- X
- X case 2:
- X cmembase = 0x080000;
- X break;
- X
- X case 3:
- X cmembase = 0x100000;
- X break;
- X }
- X /* end of switch ( Chip Addr itemnum ) */
- X break;
- X
- X case 5:
- X if (mode == WARPS) mmode = TRUE ;
- X switch( itemnum ) {
- X case 0:
- X sfmemsize = 0x000000;
- X break;
- X
- X case 1:
- X sfmemsize = 0x080000;
- X break;
- X
- X case 2:
- X sfmemsize = 0x100000;
- X break;
- X
- X case 3:
- X sfmemsize = 0x180000;
- X break;
- X }
- X /* end of switch ( SF Size itemnum ) */
- X break;
- X
- X case 6:
- X if (mode == WARPS) mmode = TRUE ;
- X switch( itemnum ) {
- X case 0:
- X sfmembase = 0xc00000;
- X break;
- X
- X case 1:
- X sfmembase = 0xc80000;
- X break;
- X
- X case 2:
- X sfmembase = 0xd00000;
- X break;
- X
- X case 3:
- X sfmembase = 0xd80000;
- X break;
- X }
- X /* end of switch ( SF Addr itemnum ) */
- X break;
- X
- X case 7:
- X switch( itemnum ) {
- X case 0:
- X fmemsize = 0x000000;
- X break;
- X
- X case 1:
- X fmemsize = 0x080000;
- X break;
- X
- X case 2:
- X fmemsize = 0x100000;
- X break;
- X
- X case 3:
- X fmemsize = 0x200000;
- X break;
- X
- X case 4:
- X fmemsize = 0x400000;
- X break;
- X
- X case 5:
- X fmemsize = 0x600000;
- X break;
- X
- X case 6:
- X fmemsize = 0x800000;
- X break;
- X }
- X /* end of switch ( Fast Size itemnum ) */
- X break;
- X
- X case 8:
- X if (mode == WARPS) mmode = TRUE ;
- X switch( itemnum ) {
- X case 0:
- X fmembase = 0x200000;
- X break;
- X
- X case 1:
- X fmembase = 0x300000;
- X break;
- X
- X case 2:
- X fmembase = 0x400000;
- X break;
- X
- X case 3:
- X fmembase = 0x500000;
- X break;
- X
- X case 4:
- X fmembase = 0x600000;
- X break;
- X
- X case 5:
- X fmembase = 0x700000;
- X break;
- X
- X case 6:
- X fmembase = 0x800000;
- X break;
- X
- X case 7:
- X fmembase = 0x900000;
- X break;
- X }
- X /* end of switch ( Fast Addr itemnum ) */
- X break;
- X }
- X /* end of switch ( menunum ) */
- X}
- X
- Xvoid wrack_sploot() /* this subprogram cashes in the chips in bad times */
- X {
- X if (log != 0) {
- X if (log & SA) {
- X (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
- X log = log & CA ;
- X }
- X if (log & S8) {
- X (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
- X log = log & C8 ;
- X }
- X if (log & S4) {
- X (void) FreeMem(sizev, (long)(sizeof(long) * frags)) ;
- X log = log & C4 ;
- X }
- X if (log & S2) {
- X (void) FreeMem(chunkv, (long)(sizeof(long) * frags)) ;
- X log = log & C2 ;
- X }
- X if (log & S1) {
- X (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
- X log = log & C1 ;
- X }
- X frags = 0;
- X warps = 0;
- X }
- X}
- X
- XSetTimer(sec, micro, timermsg)
- XULONG sec, micro;
- Xstruct IOStdReq *timermsg;
- X/* This routine simply sets the timer to interrupt us after secs.micros */
- X{
- X timermsg->io_Command = TR_ADDREQUEST; /* add a new timer request */
- X timermsg->io_Actual = sec; /* seconds */
- X timermsg->io_Length = micro; /* microseconds */
- X SendIO(timermsg); /* post a request to the timer */
- X}
- X
- Xvoid cleanup() {
- X if (timerport) {
- X Wait(timerbit);
- X GetMsg(timerport);
- X CloseDevice(timermsg);
- X DeleteStdIO(timermsg);
- X DeletePort(timerport);
- X }
- X if (GfxBase) CloseLibrary(GfxBase) ;
- X if (window) CloseWindow(window) ;
- X if (IntuitionBase) CloseLibrary(IntuitionBase) ;
- X wrack_sploot() ;
- X exit(AARRRGH) ;
- X}
- X
- Xvoid inittimer() {
- X if(!(timerport = (struct MsgPort *)CreatePort(0L, 0L)))cleanup();
- X if(!(timermsg = (struct IOStdReq *)CreateStdIO(timerport)))cleanup();
- X if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0L))cleanup();
- X
- X timerbit = 1L << timerport->mp_SigBit ;
- X SetTimer(1L, 0L, timermsg); /* set for first message */
- X}
- X
- Xvoid handle_NEWSIZE() /* short term allocations cashed in then realloc'd */
- X { /* when user hits gadget but doesn't resize window */
- X if (log & SA) {
- X (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
- X log = log & CA ;
- X }
- X if (log & S8) {
- X (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
- X log = log & C8 ;
- X }
- X if (log & S1) {
- X (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
- X log = log & C1 ;
- X barh = window->Height - SIZEGAD - DRAGBAR ; /* recalculate height */
- X barb = window->Height - SIZEGAD - 1 ; /* get new bar base position */
- X warps = barh + 1 ; /* number of storage cells to be reserved */
- X if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * warps,
- X MEMF_PUBLIC)) != 0L ) log = log | S1;
- X if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
- X MEMF_PUBLIC)) != 0L ) log = log | S8;
- X if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
- X MEMF_PUBLIC)) != 0L ) log = log | SA;
- X if (log != SOK) { /* bail out if we didn't get an allocation */
- X wrack_sploot() ;
- X things_are_cool = FALSE ; /* tell _main that we're leaving */
- X }
- X e_text.TopEdge = barb + BORDER ; /* set the E text position */
- X }
- X}
- X
- Xvoid handle_MESSAGES() {
- X unsigned long class;
- X unsigned int code, qual;
- X
- X /* Wait (1L << window->UserPort->mp_SigBit); this is rediculous! */
- X while ((message=(struct IntuiMessage *)GetMsg(window->UserPort))
- X != 0L) {
- X class = message->Class ;
- X code = message->Code ;
- X qual = message->Qualifier ;
- X ReplyMsg ;
- X switch( class ) {
- X
- X case NEWSIZE:
- X intsig = TRUE ; /* resize when done here */
- X break ;
- X
- X case MENUPICK:
- X handle_MENUPICK( class, code ) ; /* do menus ASAP */
- X break ;
- X }
- X }
- X}
- X
- Xvoid memometer() /* this subprogram draws the bar graphs */
- X {
- X long i;
- X long y;
- X
- X (void) handle_MESSAGES() ; /* go see if the user wants anything */
- X i = 0 ;
- X while ((i < barh) && (intsig == FALSE)) {
- X y = barb - i ;
- X SetAPen(window->RPort, (long)cell[i]);
- X Move(window->RPort, xl, y);
- X Draw(window->RPort, xr, y);
- X i++ ;
- X }
- X}
- X
- Xvoid shake() /* this subprogram slings down the mercury column */
- X {
- X int i;
- X
- X for (i = 0; i < barh; i++) {
- X cell[i] = YELP ;
- X }
- X}
- X
- Xvoid lockout() /* this subprogram renders a whole column in border colors */
- X {
- X (void) handle_MESSAGES() ; /* go see if the user wants anything */
- X if (intsig == FALSE) {
- X SetAPen(window->RPort, WHTP) ; /* set in the border color */
- X RectFill(window->RPort, xl, (barb - barh + 1), xr, barb) ; /* fill */
- X }
- X}
- X
- Xvoid updatewarps( wf, membase, memseg ) /* this subprogram finds changes */
- Xshort wf;
- Xlong membase, memseg ;
- X {
- X register long i ;
- X register ULONG r ;
- X register ULONG delta ;
- X register ULONG *a ;
- X
- X if (memseg == 0) {
- X (void) lockout() ;
- X return ;
- X }
- X else (void) shake() ;
- X
- X delta = (ULONG)(memseg & EVENMASK) ; /* try to avoid odd address trap */
- X r = (ULONG)(membase & EVENMASK) ; /* prefer wrong address to death */
- X for (i = 0; i < barh; i++) {
- X csum[i] = 0 ;
- X }
- X for (i = 0; i < barh; i++) {
- X for (a = (ULONG *)r; a < (ULONG *)(r + delta); a++) {
- X csum[i] ^= *a ;
- X }
- X if (oldcsum[i] != 0) cell[i] ^= GRNP ; /* enters with pens */
- X if (csum[i] == oldcsum[i]) cell[i] &= GRNP ; /* all on, condition */
- X if (csum[i] == 0) cell[i] ^= CYNP ; /* detected clears a */
- X if (oldcsum[i] == 0xffffffff) cell[i] = CYNP ;/* pen; at the end a */
- X if (csum[i] == 0xffffffff) cell[i] = GRNP ; /* logical true sets */
- X oldcsum[i] = csum[i] ; /* a pen not yet set */
- X r += delta ;
- X }
- X (void) memometer();
- X}
- X
- Xvoid updatescreen( wf, membase, memseg )
- Xshort wf;
- Xlong membase, memseg;
- X {
- X register long size ;
- X register struct MemHeader *hdr ;
- X register struct MemChunk *chunk ;
- X extern struct ExecBase *SysBase ;
- X register long *which ; /* active memlist chunk pointer */
- X register long newlimit ; /* number of chunks, incl 1 null chunk, + 1 */
- X register long newfrags ; /* number of chunks, incl null chunks, + 1 */
- X long newsize ; /* size of next request for chunkv/sizev memory, + 1 */
- X int i, j, k, l ;
- X int length ; /* length is number of chunks to be processed, + 1 */
- X BOOL cf, nf ; /* cf is "chip flag" nf is "null chunk found" flag */
- X
- X if (memseg == 0) {
- X (void) lockout() ;
- X return;
- X }
- X else (void) shake() ;
- X
- X for (i = 0; i < 3; i++) {
- X chip[i] = 0;
- X fast[i] = 0;
- X }
- X for (i = 0; i < frags; i++) {
- X chunkv[i] = 0;
- X sizev[i] = 0;
- X }
- X newfrags = 0 ;
- X newlimit = 0 ;
- X nf = FALSE;
- X Forbid() ;
- X hdr = (struct MemHeader *) SysBase->MemList.lh_Head ;
- X while (hdr->mh_Node.ln_Succ) {
- X if (hdr->mh_Attributes & MEMF_CHIP) {
- X which = chip ;
- X cf = TRUE;
- X }
- X else {
- X which = fast ;
- X cf = FALSE;
- X }
- X if (((cf == TRUE) && (wf == 0)) || ((cf == FALSE) && (wf > 0))) {
- X for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) {
- X if (which[1] < frags) chunkv[which[1]++] = (unsigned long)chunk ;
- X size = chunk->mc_Bytes ;
- X if (which[2] < frags) sizev[which[2]++] = (unsigned long)size;
- X *which += size ;
- X if (nf == FALSE) {
- X newlimit++ ;
- X if (chunkv[newfrags] == NULL) {
- X nf = TRUE;
- X }
- X }
- X newfrags++ ;
- X }
- X }
- X hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ;
- X }
- X Permit() ;
- X length = frags ;
- X if (newlimit < frags) length = newlimit ;
- X for (i = 0; i < length; i++) {
- X chunkv[i] -= membase; /* chunkv is now array offset from base */
- X sizev[i] += chunkv[i]; /* and sizev is now address of array top */
- X chunkv[i] = chunkv[i] / memseg; /* this is the number of pixels */
- X sizev[i] = sizev[i] / memseg; /* and this is the top pixel */
- X if (chunkv[i] < 0) chunkv[i] = 0 ; /* we do some bounds checking */
- X if (sizev[i] < 0) sizev[i] = 0 ;
- X if (chunkv[i] >= barh) chunkv[i] = barh - 1 ;
- X if (sizev[i] >= barh) sizev[i] = barh - 1 ;
- X if (sizev[i] - chunkv[i] < 0) sizev[i] = chunkv[i] ;
- X j = chunkv[i] ; /* from now on it will be less confusing if */
- X k = sizev[i] ; /* we assign some variables for this stuff */
- X if (sizev[i] - chunkv[i] == 0) {
- X cell[j] &= BLUP ;
- X }
- X else {
- X for (l = j; l < k; l++) {
- X cell[l] &= BLKP ;
- X }
- X }
- X }
- X (void) memometer();
- X newsize = frags ;
- X while (newsize < newlimit) {
- X newsize += EXTENSION ;
- X }
- X if (newlimit > frags) {
- X (void) FreeMem(chunkv, (long)(sizeof(long) * frags));
- X if ((chunkv = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
- X MEMF_PUBLIC)) == 0L ) {
- X log = log & C2 ;
- X }
- X (void) FreeMem(sizev, (long)(sizeof(long) * frags));
- X if ((sizev = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
- X MEMF_PUBLIC)) == 0L ) {
- X (void) FreeMem(chunkv, (long)(sizeof(long) * newsize));
- X log = log & C4 ;
- X }
- X if (log != SOK) {
- X wrack_sploot() ;
- X things_are_cool = FALSE ;
- X }
- X else frags = newsize ;
- X }
- X}
- X
- Xmain() {
- X static struct IntuiText bodyText0 =
- X {BLUP, WHTP, JAM2, 58, 10, NULL, NULL, NULL};
- X static struct IntuiText bodyText1 =
- X {BLUP, WHTP, JAM2, 42, 20, NULL, NULL, NULL};
- X static struct IntuiText bodyText2 =
- X {BLUP, WHTP, JAM2, 50, 30, NULL, NULL, NULL};
- X static struct IntuiText positiveText =
- X {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
- X static struct IntuiText negativeText =
- X {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
- X struct IntuiMessage *message;
- X ULONG class;
- X USHORT code;
- X ULONG wakeupbits;
- X long syspri;
- X char *nptr;
- X struct Task *mmtcb;
- X char oldpri;
- X int t;
- X int i;
- X USHORT colflags; /* keeps track of column positions and counts */
- X USHORT left; /* left column, left edge */
- X USHORT middle; /* middle column, left edge */
- X USHORT right; /* right column, left edge */
- X USHORT barw; /* width of each mercury column */
- X USHORT wf; /* memometer window current column number */
- X long cmemseg;
- X long sfmemseg;
- X long fmemseg;
- X long membase;
- X long memseg;
- X long memsize;
- X
- X bodyText0.IText = (UBYTE *) "WARNING! CRASH POSSIBLE";
- X bodyText1.IText = (UBYTE *) "MENU MEMORY SELECTIONS MUST";
- X bodyText2.IText = (UBYTE *) "REFERENCE EXISTING MEMORY";
- X bodyText0.NextText = &bodyText1;
- X bodyText1.NextText = &bodyText2;
- X positiveText.IText = (UBYTE *) "Risk It";
- X negativeText.IText = (UBYTE *) "Retreat";
- X
- X log = 0 ;
- X if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * BARS,
- X MEMF_PUBLIC)) != 0L ) log = log | S1;
- X if ((chunkv = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
- X MEMF_PUBLIC)) != 0L ) log = log | S2;
- X if ((sizev = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
- X MEMF_PUBLIC)) != 0L ) log = log | S4;
- X if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
- X MEMF_PUBLIC)) != 0L ) log = log | S8;
- X if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
- X MEMF_PUBLIC)) != 0L ) log = log | SA;
- X if (log != SOK) {
- X wrack_sploot() ;
- X exit(AARRRGH) ;
- X }
- X if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
- X "intuition.library",33L)) != NULL &&
- X (window=OpenWindow(&newwindow)) != NULL) {
- X if ((GfxBase = (struct GfxBase *)OpenLibrary(
- X "graphics.library", 0L)) != NULL) {
- X (void) initmenus();
- X /* rp = window->RPort ; */
- X inittimer();
- X wf = 0;
- X mmode = FALSE ;
- X mode = FRAGS ;
- X delayval = p_rate ;
- X priority = p_priority ;
- X if (priority > 0) priority = 0 ;
- X lastpri = priority ;
- X syspri = priority ;
- X nptr = NULL ;
- X mmtcb = FindTask( nptr ) ;
- X oldpri = SetTaskPri( mmtcb, syspri ) ;
- X cmemsize = p_chip << 10 ;
- X cmembase = p_chipa << 10 ;
- X sfmemsize = p_sf << 10 ;
- X sfmembase = p_sfa << 10 ;
- X if (p_fast >= 512) fmemsize = p_fast << 10 ;
- X else fmemsize = p_fast << 20 ;
- X fmembase = p_fasta << 20 ;
- X while (things_are_cool == TRUE) {
- X if (chgflag != 0) {
- X chgflag = 0 ;
- X colflags = 0 ;
- X if (cmemsize != 0) colflags = colflags | (1 << 0) ;
- X if (sfmemsize != 0) colflags = colflags | (1 << 1) ;
- X if (fmemsize != 0) colflags = colflags | (1 << 2) ;
- X switch ( colflags ) {
- X case 0:
- X barw = (WINW - (2 * BORDER)) - 1 ;
- X left = LEFT ;
- X middle = 0 ;
- X right = 0 ;
- X f_text.FrontPen = ORNP ;
- X break ;
- X
- X case 1:
- X barw = (WINW - (2 * BORDER)) - 1 ;
- X left = LEFT ;
- X middle = 0 ;
- X right = 0 ;
- X f_text.FrontPen = BLUP ;
- X break ;
- X
- X case 2:
- X barw = (WINW - (2 * BORDER)) - 1 ;
- X left = 0 ;
- X middle = LEFT ;
- X right = 0 ;
- X f_text.FrontPen = CYNP ;
- X break ;
- X
- X case 3:
- X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
- X left = LEFT ;
- X middle = (left + barw + 1) ;
- X right = 0 ;
- X f_text.FrontPen = BLUP ;
- X break ;
- X
- X case 4:
- X barw = (WINW - (2 * BORDER)) - 1 ;
- X left = 0 ;
- X middle = 0;
- X right = LEFT ;
- X f_text.FrontPen = YELP ;
- X break ;
- X
- X case 5:
- X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
- X left = LEFT ;
- X middle = 0 ;
- X right = (left + barw + 1) ;
- X f_text.FrontPen = CYNP ;
- X break ;
- X
- X case 6:
- X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
- X left = 0 ;
- X middle = LEFT ;
- X right = (middle + barw + 1) ;
- X f_text.FrontPen = YELP ;
- X break ;
- X
- X case 7:
- X barw = ((WINW - (2 * BORDER)) / 3 ) - 1 ;
- X left = LEFT ;
- X middle = (left + barw + 1) ;
- X right = (middle + barw + 1) ;
- X f_text.FrontPen = BLUP ;
- X break ;
- X } /* end of switch ( colflags ) */
- X } /* end of if ( chgflag ) */
- X cmemseg = cmemsize / barh ;
- X sfmemseg = sfmemsize / barh ;
- X fmemseg = fmemsize / barh ;
- X if (mmode == TRUE && ((sfmemsize != 0) ||
- X (fmembase != 0x200000))) {
- X /* Keep your eyes open here. If we get a negative */
- X /* response from the requester, that means either the */
- X /* user retreated, or a no-requester function such as */
- X /* noreq or KillReq has selected the negative option. */
- X /* If such functions select the positive option they */
- X /* force acceptance of the crash risk with SFmemory. */
- X
- X mode = AutoRequest(window, &bodyText0, &positiveText,
- X &negativeText, 0L, 0L, 319L, 79L) ;
- X }
- X if (mmode == TRUE && ((sfmemsize != 0) ||
- X (fmembase != 0x200000))) {
- X if (mode == FRAGS) { /* user Retreat select */
- X sfmemseg = 0 ; /* results in execution */
- X sfmemsize = 0 ; /* of this code segment */
- X fmembase = 0x200000 ; /* resetting internals */
- X }
- X }
- X switch ( wf ) {
- X case 0:
- X xl = left ;
- X membase = cmembase ;
- X memseg = cmemseg ;
- X memsize = cmemsize ;
- X break;
- X
- X case 1:
- X xl = middle ;
- X membase = sfmembase ;
- X memseg = sfmemseg ;
- X memsize = sfmemsize ;
- X break;
- X
- X case 2:
- X xl = right ;
- X membase = fmembase ;
- X memseg = fmemseg ;
- X memsize = fmemsize ;
- X break;
- X } /* end of switch ( wf ) */
- X xr = xl + barw ;
- X if (mmode == TRUE) {
- X mode = WARPS ;
- X mmode = FALSE ;
- X }
- X if (xl != 0) {
- X if (mode == WARPS) {
- X (void) updatewarps( wf, membase, memseg ) ;
- X e_text.FrontPen = YELP ;
- X }
- X if (mode == FRAGS) {
- X (void) updatescreen( wf, membase, memseg ) ;
- X e_text.FrontPen = BLUP ;
- X }
- X }
- X if (intsig == TRUE) {
- X handle_NEWSIZE() ;
- X intsig = FALSE ;
- X }
- X if (syspri != priority) {
- X syspri = priority ;
- X nptr = NULL;
- X mmtcb = FindTask( nptr ) ;
- X oldpri = SetTaskPri( mmtcb, syspri ) ;
- X }
- X if (wf == 2) {
- X PrintIText(window->RPort,&f_text,RTEXT,0L) ;
- X wakeupbits = Wait(timerbit) ;
- X if (wakeupbits & timerbit) {
- X GetMsg(timerport);
- X SetTimer(delayval, 0L, timermsg);
- X }
- X }
- X wf++ ;
- X if (wf >= 3) wf = 0 ;
- X } /* end of while ( things_are_cool) */
- X
- X if (timerport) {
- X Wait(timerbit);
- X GetMsg(timerport);
- X CloseDevice(timermsg);
- X DeleteStdIO(timermsg);
- X DeletePort(timerport);
- X }
- X
- X if (GfxBase) CloseLibrary(GfxBase) ;
- X }
- X if (window) CloseWindow(window) ;
- X if (IntuitionBase) CloseLibrary(IntuitionBase) ;
- X }
- X wrack_sploot() ;
- X}
- X
- X_cli_parse() {}
- X_wb_parse() {}
- END_OF_FILE
- if test 35050 -ne `wc -c <'mm.c'`; then
- echo shar: \"'mm.c'\" unpacked with wrong size!
- fi
- # end of 'mm.c'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
- Mail comments to the moderator at <amiga-request@cs.odu.edu>.
- Post requests for sources, and general discussion to comp.sys.amiga.
-